//
//  MyClassViewController.m
//  test1
//
//  Created by 衣尚品1 on 15/4/30.
//  Copyright (c) 2015年 衣尚品1. All rights reserved.
//

#import "MyClassViewController.h"
#import "MyClassCell.h"
#import "RCIM.h"
#import "RCChatViewController.h"

@interface MyClassViewController ()

@end

@implementation MyClassViewController{
    NSMutableArray *className;
    NSMutableArray *classTime;
    NSMutableArray *teacherName;
    NSMutableArray *imageName;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    className = [[NSMutableArray alloc] initWithObjects:@"数学",@"英语",@"钢琴", nil];
    classTime = [[NSMutableArray alloc] initWithObjects:@"15/06/23  15:30",@"15/05/12  9:30",@"15/04/14  14:00", nil];
    teacherName = [[NSMutableArray alloc] initWithObjects:@"张小燕",@"王叔晖",@"董茜", nil];
    imageName = [[NSMutableArray alloc] initWithObjects:@"will1.png",@"will1.png",@"done1.png", nil];

    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gotoTalk:) name:@"MyClassMessage" object:nil];
}

- (void)gotoTalk:(NSNotification *)sender{
    [RCIM connectWithToken:@"eCauf2imkY+0nl7yAMbB4niPfKr/+taTIwNODqO7o6pxtt8w/VcnOhd7aCh+x+wrqwiNFOJJfoO88hF53jTBGg==" completion:^(NSString *userId) {
        
        RCChatViewController *chatViewController = [[RCIM sharedRCIM] createPrivateChat:@"2" title:sender.object completion:^{
        }];
        
        [self.navigationController pushViewController:chatViewController animated:YES
         ];
        
        self.tabBarController.tabBar.hidden = YES;
        
    } error:^(RCConnectErrorCode status) {
        
    }];
}

- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return className.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 96;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdentify = @"myclassCell";
    
    UINib *nib = [UINib nibWithNibName:@"MyClassCell" bundle:nil];
    [self.MyClassTableView registerNib:nib forCellReuseIdentifier:cellIdentify];
    
    MyClassCell *cell = [[MyClassCell alloc] init];
    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    
    cell.className.text = className[indexPath.row];
    cell.classTime.text = classTime[indexPath.row];
    cell.teacherName.text = teacherName[indexPath.row];
    cell.willOrDoneImage.image = [UIImage imageNamed:imageName[indexPath.row]];

    
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self performSegueWithIdentifier:@"gotoEvaluation" sender:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
